Skip to content

Bug/bomber shortcode#57

Open
dlousa92 wants to merge 6 commits intomainfrom
bug/bomber-shortcode
Open

Bug/bomber shortcode#57
dlousa92 wants to merge 6 commits intomainfrom
bug/bomber-shortcode

Conversation

@dlousa92
Copy link
Copy Markdown
Contributor

The first two steps in issue #54 are completed. I've been looking into methods of making the bomber icon shortcode available in the toolbar.

I'm able to add a button into the toolbar using the format API so that's awesome! Screenshot below,
Screen Shot 2019-04-15 at 11 11 06 AM

However the biggest hurdle I'm having right now is how to add the shortcode into that button. There's a few methods in rich-text that are possible to use, linked here. I've been experimenting with applyFormat and toggleFormat. These do work in the sense that I'm able to insert code that's similar to the shortcode as per the screenshot below,
Screen Shot 2019-04-15 at 11 11 18 AM

The main problem is I'm unable to set an src link to the image using these methods. I can set a background url for this element with the bomber image in css, however I know that's kind of hacky.

Another possible solution I've found is that perhaps it's possible to create a Gutenberg block that would be the bomber icon and then making this block inline with css. Here is a link to an issue on the gutenberg repository that references this.

@dlousa92 dlousa92 requested a review from jnschrag April 15, 2019 15:18
@jnschrag
Copy link
Copy Markdown
Contributor

@dlousa92 Are you unable to simply insert [aircraft] into the post when the user clicks on the button? We don't want to insert HTML at all, but rather just insert the existing shortcode.

@dlousa92
Copy link
Copy Markdown
Contributor Author

I might be able to do that with an AJAX request. Researching now.

@dlousa92
Copy link
Copy Markdown
Contributor Author

Here is the code as I have it now.

Comment thread wp-content/plugins/aircraft/aircraft.js Outdated
icon: 'editor-code',
title: 'Aircraft Shortcode',
onClick: function() {
props.onChange( wp.richText.toggleFormat(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is where I need to call the shortcode to run when a user clicks on the format button. I just don't know how to actually reference that shortcode from this js file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into this!

I think part of where the confusion lies is that what we're actually trying to do is different than what the toggleFormat method does (that just happened to be what the tutorial was about). I went and looked at the richText package and there is an insert method that seems more in line with what it is we're actually trying to do, which is insert a string [aircraft] into the post.

There isn't a lot of documentation or examples out there on this, so you might have to dig a little bit to find an existing example or you'll have to figure it out from trial and error. I did find in the Gutenberg codebase the code they use for inserting a line break, which might be similar enough that you can use it for reference. Here are a few other articles I found that might point you in the right direction:

@dlousa92
Copy link
Copy Markdown
Contributor Author

It works!

@jnschrag jnschrag changed the base branch from master to main April 5, 2021 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants